/* GUI CONVERTED from rscalcld.p (converter v1.75) Sat Aug 12 23:13:48 2000 */
/* rscalcld.p - Release Management Supplier Schedules                   */
/* Copyright 1986-2002 QAD Inc., Carpinteria, CA, USA.                  */
/* All rights reserved worldwide.  This is an unpublished work.         */
/*F0PN*/ /*V8:ConvertMode=Maintenance                                   */
/* REVISION: 7.3    LAST MODIFIED: 10/12/92           BY: WUG *G462*    */
/* REVISION: 7.3    LAST MODIFIED: 03/04/93           BY: WUG *G776*    */
/* REVISION: 7.3    LAST MODIFIED: 03/18/93           BY: WUG *G776*    */
/* REVISION: 7.3    LAST MODIFIED: 03/18/93           BY: WUG *G841*    */
/* REVISION: 9.1    LAST MODIFIED: 08/12/00           BY: *N0KP* myb    */


/*
SUBPROGRAM  TO  CALCULATE  DAY,  WEEK,  MONTH  "LAST"  DATES  FOR
BUCKETING PURPOSES

THIS PROGRAM RETURNS A LAST DAY, WEEK OR MONTH DATE DEPENDING  ON
IF  THE NUMBER OF DAYS, WEEKS, MONTHS IS NON-ZERO.  OTHERWISE THE
UNKNOWN VALUE IS RETURNED.

DATES ARE "ALIGNED", EG IF DAYS > 0 AND WEEKS > 0, THEN THE  LAST
DAY  DATE  IS ADVANCED TO THE FOLLOWING SUNDAY.  IF MONTHS > 0 WE
DO THE SAME FOR THE LAST WEEK OR DAY DATE, ADVANCING  IT  TO  THE
SUNDAY THAT PRECEDES THE FIRST MONDAY  OF  THE  FOLLOWING  MONTH.
THE  LAST MONTH DATE IS THEN TAKEN FROM THAT ALIGNED DATE FOR THE
NUMBER OF MONTHS THRU THE SUNDAY PRECEDING THE  FIRST  MONDAY  OF
THE FOLLOWING MONTH.

THE DATE RETURNED FOR THE LAST WEEK OR MONTH IS ALWAYS A  SUNDAY.
THE  DATE RETURNED FOR THE LAST DAY WILL BE SUNDAY ONLY IF EITHER
A LAST WEEK OR MONTH DATE IS RETURNED.

THE REASON FOR DOING ALL THIS GOOD  STUFF  IS  BECAUSE  BUCKETING
STANDARDS  CALL  FOR  ALWAYS  HAVING  MONDAY  DATES  FOR BUCKETED
QUANTITIES.

THE ACTUAL BUCKETING IS DONE ELSEWHERE BY THE CALLING PROGRAMS.

!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!!NOTE  THAT  THIS  IS  USED  BY  BOTH  CUSTOMER   AND   SUPPLIER
SCHEDULES!!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

*/

{mfdeclre.i} /*GUI moved to top.*/
def input param asof_date as date.
def input param days as int.
def input param weeks as int.
def input param months as int.

def output param lastdaysdt as date.
def output param lastweeksdt as date.
def output param lastmthsdt as date.

def var mth_1st_mon_dt as date.
def var prior_mth_1st_mon_dt as date.
def var wk_mon_dt as date.
def var prior_wk_mon_dt as date.
def var work_dt as date.
def var work_sum as dec.
def var i as int.
def var mm as int.
def var dd as int.
def var yy as int.
def var before as log init yes.
def var after as log init no.

/*GUI moved mfdeclre/mfdtitle.*/



lastdaysdt = ?.
lastweeksdt = ?.
lastmthsdt = ?.

if days > 0 then do:
   lastdaysdt = asof_date + days - 1.
end.

if weeks > 0 then do:
   if days > 0 then do:
      {gprun.i ""rswmd.p"" "(input lastdaysdt, input before, output wk_mon_dt)"}
/*GUI*/ if global-beam-me-up then undo, leave.

      lastdaysdt = wk_mon_dt + 6.
      lastweeksdt = lastdaysdt + (weeks * 7).
   end.
   else do:
      {gprun.i ""rswmd.p"" "(input asof_date, input after, output wk_mon_dt)"}
/*GUI*/ if global-beam-me-up then undo, leave.

      lastweeksdt = wk_mon_dt + (weeks * 7) - 1.
   end.
end.

if months > 0 then do:
   if weeks > 0 then do:
      {gprun.i ""rsm1md.p"" "(input lastweeksdt + 1, input after,
      output mth_1st_mon_dt)"}
/*GUI*/ if global-beam-me-up then undo, leave.


      lastweeksdt = mth_1st_mon_dt - 1.
      lastmthsdt = mth_1st_mon_dt.
      i = 0.

      do i = 1 to months:
     {gprun.i ""rsm1md.p"" "(input lastmthsdt + 45, input before,
     output mth_1st_mon_dt)"}
/*GUI*/ if global-beam-me-up then undo, leave.


     lastmthsdt = mth_1st_mon_dt.
      end.

      lastmthsdt = lastmthsdt - 1.
   end.
   else
   if days > 0 then do:
      {gprun.i ""rsm1md.p"" "(input lastdaysdt + 1, input after,
      output mth_1st_mon_dt)"}
/*GUI*/ if global-beam-me-up then undo, leave.


      lastdaysdt = mth_1st_mon_dt - 1.
      lastmthsdt = mth_1st_mon_dt.
      i = 0.

      do i = 1 to months:
     {gprun.i ""rsm1md.p"" "(input lastmthsdt + 45, input before,
     output mth_1st_mon_dt)"}
/*GUI*/ if global-beam-me-up then undo, leave.


     lastmthsdt = mth_1st_mon_dt.
      end.

      lastmthsdt = lastmthsdt - 1.
   end.
   else do:
      {gprun.i ""rsm1md.p"" "(input asof_date, input after,
      output mth_1st_mon_dt)"}
/*GUI*/ if global-beam-me-up then undo, leave.


      lastmthsdt = mth_1st_mon_dt.

      do i = 1 to months:
     {gprun.i ""rsm1md.p"" "(input lastmthsdt + 45, input before,
     output mth_1st_mon_dt)"}
/*GUI*/ if global-beam-me-up then undo, leave.


     lastmthsdt = mth_1st_mon_dt.
      end.

      lastmthsdt = lastmthsdt - 1.
   end.
end.
